package com.iexbuy.ihg.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.iexbuy.ihg.R;
import com.iexbuy.ihg.entity.CommonQuestion;
import com.iexbuy.ihg.entity.ReComment;
import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class WeDeCommonQuestionDetailFragment extends BaseFragment {

	private static WeDeCommonQuestionDetailFragment homeFragmentInstent;

	@ViewInject(R.id.msgListLayout)
	private PullToRefreshLayout msgListRefreshLayout;
	@ViewInject(R.id.title)
	private TextView title;
	@ViewInject(R.id.detail)
	private WebView detail;

	private static CommonQuestion commonQuestion;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		homeFragmentInstent = this;
	}

	@Override
	protected View _onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_wede_common_question_detail, container, false);
		ViewUtils.inject(this, rootView);
		initView(rootView);
		return rootView;
	}

	private void initView(View rootView) {
		mBaseActivity.setTitle(getResources().getString(R.string.we_de_common_question_detail));
		mBaseActivity.setTitleLayoutVisibility(true);
		mBaseActivity.setHomeActivity(false);

		initRecommentView();
	}

	private void initRecommentView() {
		if (commonQuestion == null) {
			return;
		}
		title.setText(commonQuestion.getTitle());
		//商品详情html
		detail.getSettings().setDefaultTextEncodingName("UTF-8");
		detail.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
		detail.getSettings().setLoadWithOverviewMode(true);
		detail.loadData(commonQuestion.getContent(), "text/html; charset=UTF-8", null);
	}


	public static void setCommonQuestion(CommonQuestion commonQuestion) {
		WeDeCommonQuestionDetailFragment.commonQuestion = commonQuestion;
	}

	/**
	 * @return the homeFragmentInstent
	 */
	public static WeDeCommonQuestionDetailFragment getHomeFragmentInstent() {
		return homeFragmentInstent;
	}

}
